package com.whosly.study.webflux.config;

import com.whosly.study.webflux.service.GreetingServiceImpl;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class GRPCConfiguration implements InitializingBean {

    @Override
    public void afterPropertiesSet() throws Exception {
        Server server = ServerBuilder.forPort(8081)
                .addService(new GreetingServiceImpl())
                .build();

        // Start the server
        server.start();

        // Server threads are running in the background.
        System.out.println("GRPC Server started, port: " + 8081);
    }

}
